﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace FlickrSL.Data
{
    public class EchoParameterCollection : Dictionary<String, String>
    {
        public EchoParameterCollection()
        {
        }

        public EchoParameterCollection(Int32 capacity)
            : base(capacity)
        {
        }

        public EchoParameterCollection(params KeyValuePair<String, String>[] pairs)
            : base(pairs.Length)
        {
            foreach (KeyValuePair<String, String> pair in pairs)
            {
                this.Add(pair.Key, pair.Value);
            }
        }

        public EchoParameterCollection(params String[] parameters)
            : base(parameters.Length >> 1)
        {
            if ((parameters.Length & 1) != 0)
            {
                throw new ArgumentException("Incorrect Number of Parameters");
            }

            for (Int32 i = 0; i < parameters.Length - 1; i += 2)
            {
                this.Add(parameters[i], parameters[i + 1]);
            }
        }

        public override string ToString()
        {
            return String.Join("&", this.Select(kvp => kvp.Key + "=" + kvp.Value));
        }
    }
}
